package com.infore.airsupervise.bean;

import android.content.Context;
import android.content.SharedPreferences;

import com.alibaba.fastjson.JSON;
import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.app.MyApplication;

import java.util.List;

/**
 * @features:
 * @author: WuTao
 * @date: 2017/3/21 15:20
 */
public class UserE extends BaseEntity{

    /**
     * realName : 超级用户
     * password : root
     * account : root
     * token : 6dbe92aaac2030a766563364196d0807
     */

    private String realName;
    private String password;
    private String account;
    private String token;
    private String userId;
    /**
     * address : 佛山市里水镇流潮社区
     * grid : 流潮社区居委会
     * lat : 22.8537204138
     * lnt : 113.2656279822
     * missionList : [{"discrib":"巡检任务","startTime":"2017-04-15 17:44:10","id":"28                              ","endTime":"2017-04-20 00:00:00","title":"伦教地区日常巡检任务","missionNum":"Mlisi1492249270389"},{"discrib":"伦教地区监控站设备例行巡检","startTime":"2017-04-15 17:37:56","id":"27                              ","endTime":"2017-04-19 00:00:00","title":"监控站例行巡检任务","missionNum":"Mlisi1492248939196"}]
     * phone : 13165425685
     */

    private String address;
    private String grid;
    private double lat;
    private double lnt;
    private String phone;
    private List<MissionE> missionList;
    private String upDateTime;

    public List<MissionE> getMissionList() {
        return missionList;
    }

    public void setMissionList(List<MissionE> missionList) {
        this.missionList = missionList;
    }

    public String getUpDateTime() {
        return upDateTime;
    }

    public void setUpDateTime(String upDateTime) {
        this.upDateTime = upDateTime;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getGrid() {
        return grid;
    }

    public void setGrid(String grid) {
        this.grid = grid;
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLnt() {
        return lnt;
    }

    public void setLnt(double lnt) {
        this.lnt = lnt;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * 保存用户登录信息
     */
    public static void saveUserInfo( UserE userE){
        SharedPreferences sp=  MyApplication.getInstance().getSharedPreferences(Constants.SP_FILE_USER,Context.MODE_PRIVATE);
        SharedPreferences.Editor editor =sp.edit();
        String str_user= JSON.toJSONString(userE,false);
        editor.putString(Constants.SP_USER_INFO_KEY,str_user);
        editor.commit();
    }

    /**
     * 获取用户登录信息
     */
    public static UserE getUserInfo(){
        SharedPreferences sp=  MyApplication.getInstance().getSharedPreferences(Constants.SP_FILE_USER,Context.MODE_PRIVATE);
        UserE userE=JSON.parseObject(sp.getString(Constants.SP_USER_INFO_KEY,""),UserE.class);
        return userE;
    }

    /**
     * 保存登录状态
     */
    public static void setLoginStatus(boolean loginStatus){
        SharedPreferences sp = MyApplication.getInstance().getSharedPreferences(Constants.SP_FILE_USER,Context.MODE_PRIVATE);
        SharedPreferences.Editor editor =sp.edit();
        editor.putBoolean(Constants.SP_LOGIN_STATE_KEY,loginStatus);
        editor.commit();
    }
    /**
     * 获取登录状态
     */
    public static boolean getLoginStatus(){
        SharedPreferences sp = MyApplication.getInstance().getSharedPreferences(Constants.SP_FILE_USER,Context.MODE_PRIVATE);
        return sp.getBoolean(Constants.SP_LOGIN_STATE_KEY,false);
    }

    /**
     * 清空登录状态和数据
     */

    public static void  cleanLoginInfo(){
        SharedPreferences sp = MyApplication.getInstance().getSharedPreferences(Constants.SP_FILE_USER,Context.MODE_PRIVATE);
        sp.edit().clear().commit();
    }

    /**
     * 保存全部人员信息
     *
     */
    public static void saveAllPson(List<UserE> userEList){
        SharedPreferences sp = MyApplication.getInstance().getSharedPreferences(Constants.SP_FILE_USER,Context.MODE_PRIVATE);
        SharedPreferences.Editor editor =sp.edit();
        String str_allPson = JSON.toJSONString(userEList);
        editor.putString(Constants.SP_ALLPSON_KEY,str_allPson).commit();
    }
    /**
     * 获取全部人员
     */
    public static List<UserE> getAllPson(){
        SharedPreferences sp = MyApplication.getInstance().getSharedPreferences(Constants.SP_FILE_USER,Context.MODE_PRIVATE);
        List<UserE> userEList= JSON.parseArray(sp.getString(Constants.SP_ALLPSON_KEY,""),UserE.class);
        return userEList;
    }

    public static void saveToken(String token) {
        SharedPreferences sp = MyApplication.getInstance().getSharedPreferences(Constants.SP_FILE_USER,Context.MODE_PRIVATE);
        sp.edit().putString(Constants.SP_VIDEO_TOKEN_KEY, token)
                .commit();
    }

    public static String getVideoToken(){
        SharedPreferences sp = MyApplication.getInstance().getSharedPreferences(Constants.SP_FILE_USER,Context.MODE_PRIVATE);
        return sp.getString(Constants.SP_VIDEO_TOKEN_KEY,"");
    }
}
